Compact Representation: Store multiple attributes (features) in a single mathematical object.
Efficient Computation: Operations on vectors (addition, dot product) can be parallelized (SIMD).
Geometric Interpretation: Allows us to visualize data relationships (distance, angle).
Basis for Matrix/Tensor: Foundation for representing higher-dimensional data and transformations.
Tip
In AI, we treat everything (images, text, audio) as vectors to apply mathematical transformations!
Vector Operations (Addition)
Vector Addition Animation
Addition: \((r + s = s + r)\), commutative & associative
Parallelogram Rule: tip-to-tail method
r = [3, 2] (red vector)
s = [1, -1] (blue vector)
r + s = [4, 1] (green vector)
Dashed lines show parallelogram construction
Vector Operations (Scalar Multiplication)
Scalar Multiplication Animation
Scalar Multiplication: scales length, preserves/reverses direction
Original vector v = [3, 2] (blue)
0.5v: half length, same direction (orange)
1.5v: 1.5× length, same direction (green)
-v: same length, opposite direction (red)
All vectors are collinear (same line)
The Rules of the Game
The intuitive operations we performed follow a consistent set of rules. These rules define the structure that our vectors live in.
Vector Addition \((+: V \times V \to V)\)
\(x + y = y + x\)(Commutativity)
\((x + y) + z = x + (y + z)\)(Associativity)
Existence of a null vector (\(x + 0 = x\))
Existence of an additive inverse (\(x + (-x) = 0\))
Scalar Multiplication \((\cdot: \mathbb{F} \times V \to V)\)
\(a(bx) = (ab)x\)(Associativity)
\(a(x + y) = ax + ay\)(Distributivity)
\((a + b)x = ax + bx\)(Distributivity)
\(1x = x\)(Identity element)
A Vector Space Defined
This collection of objects and rules forms a vector space. It is a mathematical structure \((V, \mathbb{F}, +, \cdot)\) where:
\(V\) is a set of vectors(like our Iris data points).
\(\mathbb{F}\) is a field of scalars(for us, the real numbers \(\mathbb{R}\)).
\(+\) is the vector addition operation.
\(\cdot\) is the scalar multiplication operation.
Key Insight: Our Iris dataset, represented as tuples in \(\mathbb{R}^4\), forms a vector space. This is the structure that guarantees our scaling operations are mathematically sound. The definition is not arbitrary; it’s formalised in hindsight to capture our geometric intuition.
TABLE OF CONTENTS
1. Introduction✓
2. What are Vectors?✓
3. The Formal Structure●
4. Coordinate Systems & Basis○
5. Vector Norms○
6. The Dot Product○
7. Python: NumPy○
Vector Space Requirements
Let \(V\) be a set of vectors and \(\mathbb{F}\) a field of scalars. \(V\) is a vector space over \(\mathbb{F}\) if:
Closure under addition\(u, v \in V \implies u + v \in V\)
Additive identity\(\exists 0 \in V\) such that \(v + 0 = v\)
Additive inverse\(\forall v \in V, \exists (-v) \in V\) such that \(v + (-v) = 0\)
Closure under scalar multiplication\(a \in \mathbb{F}, v \in V \implies av \in V\)
Distributivity over vector addition\(a(u + v) = au + av\)
Distributivity over scalar addition\((a + b)v = av + bv\)
Scalar identity\(1v = v\)
\((V, \mathbb{F}, +, \cdot)\) is a vector space over \(\mathbb{F}\) if it satisfies the above properties.
Vectors Terminology
What is this notation? (\(\mathbb{Z}_2^3, \mathbb{Z}_2, +, \cdot\))
\(\mathbb{Z}_2\): The set of scalars \(\{0, 1\}\).
\(\mathbb{Z}_2^3\): Vectors of length 3 where entries are from \(\mathbb{Z}_2\).
Example: \((1, 0, 1) \in \mathbb{Z}_2^3\).
\(+\): Component-wise addition modulo 2.
\(\cdot\): Scalar multiplication modulo 2.
Check Your Understanding 2
Let’s warm up with “Binary Arithmetic” (where \(1+1=0\)).
In \(\mathbb{Z}_2\), what is \(1 + 1 + 1\)? Answer: 1 (since \(1+1=0\), then \(0+1=1\))
In \(\mathbb{Z}_2^3\), compute \(\mathbf{u} + \mathbf{v}\) for \(\mathbf{u}=(1,0,1)\) and \(\mathbf{v}=(1,1,0)\). Answer: (0, 1, 1)
Is the vector \((2, 0)\) in \(\mathbb{Z}_2^2\)? Answer: No (Elements must be 0 or 1)
Exercise
Show that \((\mathbb{Z}_2^2, \mathbb{Z}_2, +, \cdot)\) is a vector space.
Proof Sketch: Check the 7 requirements for vectors \(\mathbf{u} = (u_1, u_2) \in \mathbb{Z}_2^2\):
Closure (+):\((u_1+v_1, u_2+v_2) \in \mathbb{Z}_2^2\) since sums are mod 2.
We represent the vector \(\mathbf{v}\) with the coordinate pair \((3, 2)\).
This is shorthand for saying we take 3 steps along the first axis and 2 steps along the second.
These “steps” are defined by a special set of vectors: \(\mathbf{e}_1\) and \(\mathbf{e}_2\).
Defining the Basis
The basis vectors are the fundamental reference directions we agree upon.
For 2D space (\(\mathbb{R}^2\)), we typically use:
\(\mathbf{e}_1 = (1, 0)\) : “One step East”
\(\mathbf{e}_2 = (0, 1)\) : “One step North”
Every other vector is just a weighted sum of these two.
Think of it like a recipe:
If \(\mathbf{e}_1\) is “Cups of Flour” and \(\mathbf{e}_2\) is “Cups of Sugar”…
Then the vector \(\mathbf{v} = (3, 2)\) is the mix: \[ 3 \times \text{Flour} + 2 \times \text{Sugar} \]
Linear Combinations
Coordinates are simply the instructions - the recipe - for building a vector using a pre-agreed set of “building block” vectors.
This recipe is called a linear combination.
The same vector can have different coordinates if we change the building blocks.
Our mission is to understand what makes a good set of building blocks.
Check Your Understanding 1
If we choose a different set of basis vectors to describe the same physical arrow \(\mathbf{v}\):
Suppose our new basis vectors are twice as long (\(\mathbf{u}_1 = 2\mathbf{e}_1, \mathbf{u}_2 = 2\mathbf{e}_2\)). To build the same vector \(\mathbf{v}\) that was \((4, 6)\) before, what are the new coordinates?
The Span
For a set of vectors \(S = \{\mathbf{u}, \mathbf{v}\}\), its span is the set of all possible linear combinations of those vectors.
If \(\text{span}(S) = V\), we say \(S\) is a generating set for the vector space \(V\).
Linear Independence: Is this a Basis?
Consider the set \(S = \{v_1, v_2, v_3\}\) where: \[v_1 = (1,0), \quad v_2 = (0,1), \quad v_3 = (1,1)\]
Question: Is \(S\) a basis for \(\mathbb{R}^2\)?
Answer:No.
Why? Because it contains redundant information (violates independence). For example, the vector \((2,1)\) has multiple recipes:
\[ (2,1) = 2v_1 + v_2 \]\[ (2,1) = v_1 + v_3 \]
Defining the Basis
The ideal ‘skeleton’ for a vector space must have maximum reach and zero redundancy. This perfect set is called a basis.
Definition 4. (Basis)
Let \(V\) be a vector space and \(S\) be a subset of its vectors. \(S\) is a basis of \(V\) if:
(a) \(S\) is linearly independent.(Efficiency)
(b) \(\text{span}(S) = V\).(Reach)
How to Check if a Set is a Basis?
The “Goldilocks” Test: Compare vector count (\(k\)) to dimension (\(n\)).
\(k < n\)
Too Few
Cannot span space
\(k = n\)
Just Right?
Check Determinant \(\neq 0\)
\(k > n\)
Too Many
Must be dependent
Or test manually for linear independence!
A Basis Hits the Sweet Spot
A basis is perfectly balanced. It contains the exact amount of information needed to describe the entire space, no more and no less.
Property 1: Maximal Linear Independence
Adding any other vector from the space to a basis will make the set linearly dependent.
A basis is a maximal linearly independent set.
Property 2: Minimal Generating Set
Removing any single vector from a basis means it can no longer span the entire space.
A basis is a minimal generating set.
Every vector in a basis is essential.
Exercise.
Are the following vector sets linearly independent?
#> Check if vectors are linearly independent#> by computing the determinant of the matrix they formS = np.array([ [1, 0, 0], [1, 1, 0], [1, 1, 1]])det = np.linalg.det(S)print(f"Matrix:\n{S}")print(f"Determinant = {det:.1f}")print(f"Linearly Independent? {'Yes'if det !=0else'No'}")
document.addEventListener("DOMContentLoaded", function() {
function handleQuizClick(e) {
// Find closest list item
const li = e.target.closest('li');
if (!li) return;
// Find the checkbox strictly within this LI (not nested deeper)
// We can check if the checkbox's closest LI is indeed this LI.
const checkbox = li.querySelector('input[type="checkbox"]');
if (!checkbox) return;
// Verify strict parent-child relationship to avoid triggering when clicking parent Question LI
if (checkbox.closest('li') !== li) return;
// We found a quiz item!
// Prevent default only if we are handling it.
// If the user clicked the checkbox directly, it might toggle. We want to force it to our logic.
e.stopPropagation();
// Determine correctness
// Quarto/Pandoc sets the 'checked' attribute for [x] items in the HTML source
// We rely on the attribute because the 'checked' property might have been toggled by the click before we got here if we didn't preventDefault fast enough.
// Actually, getting the initial state is safer.
const isCorrect = checkbox.hasAttribute('checked');
// Force the checkbox to match its "correct" state visually (optional, but good for consistency)
// checkbox.checked = isCorrect;
// We just want feedback colors.
// Reset classes
li.classList.remove('quiz-correct', 'quiz-incorrect');
// Apply feedback
if (isCorrect) {
li.classList.add('quiz-correct');
} else {
li.classList.add('quiz-incorrect');
}
}
function initQuiz() {
// Enable checkboxes and style them
const checkboxes = document.querySelectorAll(".reveal .slides li input[type='checkbox']");
checkboxes.forEach(cb => {
cb.disabled = false;
// Prevent default browser toggling logic on the input itself, let our handler manage expectation
cb.onclick = function(e) { e.preventDefault(); };
const li = cb.closest('li');
if (li) {
li.classList.add('quiz-option');
// Direct listener on LI is sometimes more reliable than delegation in complex frameworks
li.removeEventListener('click', handleQuizClick);
li.addEventListener('click', handleQuizClick);
}
});
}
// Initialize on Reveal ready
if (window.Reveal) {
if (window.Reveal.isReady()) {
initQuiz();
} else {
window.Reveal.on('ready', initQuiz);
}
window.Reveal.on('slidechanged', initQuiz);
// Also on fragment shown, as content might appear
window.Reveal.on('fragmentshown', initQuiz);
} else {
initQuiz();
}
});